package com.improvess.rna.som.loaddata;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;

import com.improvess.rna.som.DataSet;

public class LoadData {
	
	public static DataSet loadConjuntoDeTreinamento(File file) throws IOException {
		FileInputStream fileInputStream = new FileInputStream(file);
		Scanner scanner = new Scanner(fileInputStream);
		
		int quantidadeDeRegistros = scanner.nextInt();
		int atributos = scanner.nextInt();

		double [] [] registros = new double [quantidadeDeRegistros][atributos];
		String [] clazzes = new String[quantidadeDeRegistros];
		
		for(int i = 0; i < quantidadeDeRegistros; i++){
			double [] x = new double[atributos];
			for(int k = 0; k < atributos ; k++){
				x[k] = scanner.nextDouble();
			}
			
			String label = scanner.next();
			
			registros[i] = x;
			clazzes[i] = label;
			
		}
		
		scanner.close();
		fileInputStream.close();
				
		return new DataSet(file.getName(), registros, clazzes);
	}

}
